home *** CD-ROM | disk | FTP | other *** search
/ Singles Flirt Up Your Life! (German) / Singles Flirt Up Your Life.iso / data1.cab / Statemachine / chair.lua < prev    next >
Text File  |  2004-01-29  |  2KB  |  50 lines

  1. -- chair state machine
  2.  
  3. beginStateMachine()
  4.  
  5.     onMsg("buildMenu", function(msg)
  6.         if (repairMenu()) then return end
  7.         
  8.         -- build the pie menu
  9.         clearPieMenu();
  10.         local button ;
  11.         button = addPieMenuButton("pm_sitdown", "sit");
  12.         button.addDescription(ACTIVITY, "sit");
  13.         -- button.addIcon("guiIconComfort");
  14.     end )
  15.     
  16.     -- sit on armchair
  17.     onMsg("sit", function(msg)
  18.         -- get the game object server
  19.         local gameObjectServer = getGameObjectServer();
  20.         -- get character who initiated this action
  21.         local character = getStateObjectFromID(msg.sender);
  22.         -- walk to the closest action point
  23.         local actionPoint = nil;
  24.         local table = getTableForChair(this);
  25.         if (table) then
  26.             actionPoint = character.getClosestFreeActionPointToClickPoint(this, {"sit1", "sit2"});
  27.         else
  28.             actionPoint = character.getClosestFreeActionPointToClickPoint(this, {"sit3"});
  29.         end
  30.         -- get the walk state object
  31.         local wso = character.walkSO;
  32.         if (actionPoint) then
  33.             -- create state machine contexts
  34.             local wsoContext = StateMachineContext();
  35.             -- store the action point
  36.             wsoContext.storeData("actionPointName", actionPoint.getName());
  37.             if (wso.walkToActionPoint(actionPoint)) then
  38.                 wso.queueStateMachine("chairChar.sitDown", this, wsoContext);
  39.             else
  40.                 print("no path found");
  41.                 instantAbort(character, EMOTICON_NOPATH, "emoThink")
  42.             end
  43.         else
  44.             print("no action point found");
  45.             instantAbort(character, EMOTICON_CANNOT, "emoThink")
  46.         end
  47.     end )
  48.             
  49. endStateMachine()
  50.